<?php
/**
 * 等级头衔管理
 */
defined('IN_YuLin') || exit('NO PERMIT!');
$operation = NoBadStr($_GET['operation']);
$showPage  = '';
$levelTab  = Table('user_level');
if (IS_POST){
    $post = $_POST['data'];
    $id   = NoBadStr($post['id']);
    $ins  = array(
        'level'       => NoBadStr($post['level']),
        'title'       => NoBadStr($post['title']),
        'group_point' => NoBadStr($post['group_point']),
        'reward'      => NoBadStr($post['reward']),
        'overstep'    => NoBadStr($post['overstep']),
        'status'      => NoBadStr($post['status']),
    );
    if ($id){
        $sql = 'UPDATE ' . $levelTab . ' SET ' . CreateUpdateSql($ins) . ' WHERE id = ' . $id;
    }else{
        $sql = 'INSERT INTO ' . $levelTab . ' SET ' . CreateUpdateSql($ins);
    }
    $flag = $db->exec($sql);
    if ($flag){
        ShowMsg('操作成功', U('user/level'));
    }else{
        ShowMsg('操作失败', -1);
    }
}

switch ($operation){
    case 'addview':
        $id        = NoBadStr($_GET['id']);
        if ($id){
            $sql       = 'SELECT id, level, title, group_point, reward, overstep, status FROM ' . $levelTab . ' WHERE id = ' . $id;
            $info      = $db->getrow($sql);
        }
        $showPage  = 'user/level_add';
        break;
    case 'del':
        $id        = NoBadStr($_GET['id']);
        $sql       = 'DELETE FROM ' . $levelTab . ' WHERE id = ' . $id;
        $flag      = $db->exec($sql);
        if ($flag){
            ShowMsg('操作成功', U('user/level'));
        }else{
            ShowMsg('操作失败', -1);
        }
        break;
    default:
        $sql       = 'SELECT id, level, title, group_point, reward, overstep, status FROM ' . $levelTab;
        $levelList = $db->getall($sql);
        $showPage  = 'user/level';
        break;
}
$tpl->display($showPage);
